package com.circle.interests.biz.api;

import com.circle.interests.biz.core.PrizeInventoryManageService;
import com.circle.interests.biz.core.protocol.InventoryAllocateCondition;
import com.circle.interests.biz.enums.SceneTypeEnum;
import com.circle.interests.biz.service.IPrizeWinRecordService;
import com.circle.prize.library.api.dto.*;
import com.circle.prize.library.api.service.DubboActPrizeService;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboService;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author zhou
 * @date 2021/12/5
 */
@Slf4j
@DubboService
public class DubboActPrizeServiceImpl implements DubboActPrizeService {

    @Resource
    private IPrizeWinRecordService prizeWinRecordService;
    @Resource
    private PrizeInventoryManageService prizeInventoryManageService;

    @Override
    public void allocateActInventory(String actCode, List<PrizeInventoryDto> prizeInventoryList) {
        InventoryAllocateCondition condition = new InventoryAllocateCondition();
        condition.setSceneType(SceneTypeEnum.ACT.getCode());
        condition.setSceneId(actCode);
        condition.setPrizeInventoryList(prizeInventoryList);
        prizeInventoryManageService.allocateInventory(condition);
    }

    @Override
    public PrizeWinResultDto winPrize(String actCode, String openId, String prizeCode) {
        return prizeWinRecordService.winPrize(SceneTypeEnum.ACT.getCode(), actCode, openId, prizeCode, 1, null);
    }

    @Override
    public PrizeWinResultDto winPrize(String actCode, String openId, String prizeCode, Integer price) {
        return prizeWinRecordService.winPrize(SceneTypeEnum.ACT.getCode(), actCode, openId, prizeCode, 1, price);
    }

    @Override
    public PrizeReceiveResultDto receivePrize(Long recordId, String writeOffQrCode) {
        return prizeWinRecordService.receivePrize(recordId, writeOffQrCode);
    }

    @Override
    public void expirePrize(Long recordId) {
        prizeWinRecordService.expirePrize(recordId);
    }

    @Override
    public void recyclePrize(Long recordId) {
        prizeWinRecordService.recyclePrize(recordId);
    }

    @Override
    public UserPrizeDto writeOff(WriteOffDto writeOffDto) {
        return prizeWinRecordService.writeOff(SceneTypeEnum.ACT.getCode(), writeOffDto.getActCode(),
                writeOffDto.getPhoneNumber(), writeOffDto.getWriteOffCode(), writeOffDto.getRemark());
    }
}
